<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<%
        String basePath = "http://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath();
%>
<title>${promptInfo.totalDescInfo}</title>
<head>
<script type="text/javascript">
$(document).ready(function(){

	var jdata = {
	    globalParam:'',
		//树是否全部展开true：展开,false:合并
		isOpen:'true',
   		//列表树结构显示字段是否有复选框 
   		treeCheckbox: 'true',
   		//父亲节点是否可操作（true：可操作 false：不可操作）
   		isParentNodeOpt:'true',
		//列表要显示的列（在json中对应的key）
		tableShowColumn: ['roleName','roleID','roleParentID'],
		//列表头显示名称
		tableColumnName:   ['用户组名称','用户组ID','用户组父ID'],
		//列表头宽度
		tableColumnWidth:   ['40%','30%','30%'],
		//可以作为主键的类，在页面传送的过程中为paramMap.key{1}(主键个数值)=value的形式
		//多个主键的时候为["orgID","orgCode"]:paramMap.key1=value&paramMap.key2=value
		primkeyColumn:["roleID"],
		//要增加链接的列，可以为多个
		tableLinkColumn:[],
		//要进行树型显示的列，支持一列
		treeShowColumn:'roleName',
		//树型菜单，起始根值
		treeNodeStartValue:'0',
		//属性菜单子列
		treeChildColumn:'roleID',
		//属性菜单父列
		treeParendColumn:'roleParentID',
		ajax:{
			//ajax请求url
			url:'ajaxAction.action', 
			//ajax请求参数
			data:'code=${pmsIndex.sys_user_role_info.code}&paramMap.userCreator=${paramMap.userCreator}'//列出用户可选的用户组，只能在用户创建者所属用户组中进行选择
		}
		//tableTreeData:eval(info)
	};
	var jinitData = {
		//ajax请求url
		url:		'ajaxAction.action',
		//ajax提交方式
		type:	    'post',
		//ajax请求超时时长
		timeout:	'60000',
		//ajax请求参数
		data:	'code=${pmsIndex.sys_user_role_info_selected.code}&paramMap.userID=${paramMap.userID}',//勾选出user已绑定的userGroup
		//请求数据类型，包括json和xml两种
		dataType:	'json',
		//ajax执行前调用函数
		beforeSend:function(request){},
		//ajax请求完成后调用函数
		complete:function(request,textStatus){},
		//ajax请求成功调用函数
		success:function(jsonData,textStatus){
			//如果正常返回,设置GRIDTREE.data.tableTreeData
			//为ajax请求放回的json格式的数据
			if (textStatus == "success"){
				$("#gridTreeTable tbody tr .jq_treeCheckbox").each(function(i){
					var cval = $(this).val();
					var userID = $("#userID").val();
					if (jsonData.data){
						for (var i=0; i<jsonData.data.length;i++){
							var urmUserID = jsonData.data[i].urmUserID;
							var urmRoleID = jsonData.data[i].urmRoleID;
							if (userID && userID ==urmUserID 
									&& cval && urmRoleID && urmRoleID == cval){
								$(this).attr("checked","checked");
							}
						}
					} 
				});						
			}
		},
		//ajax请求错误后调用函数
		error:function(request,textStatus,error){}
	};	
	
	var joption = {
		extendInit:function(){
			$.ajax(jinitData);	
		},
		checkboxClick:function($obj){
			var id = $obj.attr("id");
			if ($obj.attr("checked")){
				var arr = id.split("-");
				var tmpid = '';
				for (var i=0; i<arr.length;i++){
					if (i == 0){
						if (id != arr[i]){
							tmpid = arr[i];
							$("#"+tmpid).attr("checked",true);
						}
					}
					else{
						if (id != tmpid + "-" + arr[i]){
							tmpid = tmpid + "-" + arr[i];
							$("#"+tmpid).attr("checked",true);
						}
					}
				}
			}
			else{
				$("#gridTreeTable tbody tr .jq_treeCheckbox[type='checkbox']:checked").each(function(){
					if ($(this).attr("id").indexOf(id) > -1){
						$(this).attr("checked",false);
					}
				});
			}
		}
	};
	$('#gridTree').gridTreeTB(jdata,joption);	
	$('#selectAll').click(function(){
		var $ca = $(this);
		if ($ca.attr("checked") == true){
			$("#gridTreeTable tbody tr .jq_treeCheckbox[type='checkbox']").each(function(){
					$(this).attr("checked",true);
			});	
		}
		else{
			$("#gridTreeTable tbody tr .jq_treeCheckbox[type='checkbox']").each(function(){
				if($(this).attr("disabled") == false){
					$(this).attr("checked",false);
				}
			});				
		}		
	});	
});
</script>
</head>
<body >
<form name="actionForm" method="post" action="operateAction.action" id="actionForm">
<input type="hidden" name="paramMap.userID" id="userID" value="${paramMap.userID}">
<input type="hidden" name="code" value="${pmsIndex.sys_user_bind.code}">
<input type="hidden" name="imitateStep" value="${pmsIndex.sys_user_mgr.imitationStep}"> 
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableC">
    <tr>
       <td class="tableCleft">&nbsp;</td>
       <td class="tableCcenter">
           <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="SkyTDLine">
			 <tr class="MeNewTDLine" align="center">
				<td>
			    	<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="SkyTableLine">
			         <tr>
			           <td class="SkyTDLine" align="left" style="background:#9CC7FF;height:20;" >
				 		<input type="checkbox" id="selectAll">全选
				     </td>
			           </tr>
			         </table>
				</td>
			  </tr>
               <tr>
                   <td valign="top" id="gridTree" class="MeNewTDLine"></td>
               </tr>
			   <tr class="MeNewTDLine" align="center">
				   <td  class="SkyTDLine" height="20">
                    <input type="submit" name="BtnOk" value="绑  定" id="BtnOk" class="SkyButtonBlur" onMouseOut="this.className='SkyButtonBlur'" onMouseOver="this.className='SkyButtonFocus'" />&nbsp;&nbsp;
                    <input type="button" name="BtnOk" value="返  回" id="BtnOk" class="SkyButtonBlur" onMouseOut="this.className='SkyButtonBlur'" onMouseOver="this.className='SkyButtonFocus'" onclick="window.history.back();"  />
                   </td>
			    </tr>
           </table>
       </td>
       <td class="tableCright">&nbsp;</td>
    </tr>
</table>
</form>
</body>
</HTML>
